#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int leftsum = 0;int rightsum = 0;int ans = -1;int size1 = nums.size();
        vector<int>dp;
        dp.push_back(nums[0]);
        for (int i = 1;i < size1;i++)dp.push_back(dp[i - 1] + nums[i]);
        for (int i = 0;i < size1;i++)
        {
            leftsum = dp[i] - nums[i];
            rightsum = dp[size1 - 1] - dp[i];
            if (leftsum == rightsum)return i;
        }
        return ans;
    }
};